package com.flxz.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flxz.common.annotation.Log;
import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.common.enums.BusinessType;
import com.flxz.forum.domain.ForumFavorite;
import com.flxz.forum.service.IForumFavoriteService;
import com.flxz.common.utils.poi.ExcelUtil;
import com.flxz.common.core.page.TableDataInfo;

/**
 * 讨论收藏Controller
 * 
 * @author fl
 * @date 2025-09-14
 */
@RestController
@RequestMapping("/forum/favorite")
public class ForumFavoriteController extends BaseController
{
    @Autowired
    private IForumFavoriteService forumFavoriteService;

    /**
     * 查询讨论收藏列表
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:favorite:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumFavorite forumFavorite)
    {
        startPage();
        List<ForumFavorite> list = forumFavoriteService.selectForumFavoriteList(forumFavorite);
        return getDataTable(list);
    }

    /**
     * 导出讨论收藏列表
     */
    @PreAuthorize("@ss.hasPermi('forum:favorite:export')")
    @Log(title = "讨论收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumFavorite forumFavorite)
    {
        List<ForumFavorite> list = forumFavoriteService.selectForumFavoriteList(forumFavorite);
        ExcelUtil<ForumFavorite> util = new ExcelUtil<ForumFavorite>(ForumFavorite.class);
        util.exportExcel(response, list, "讨论收藏数据");
    }

    /**
     * 获取讨论收藏详细信息
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:favorite:query')")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(forumFavoriteService.selectForumFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增讨论收藏
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('forum:favorite:add')")
    @Log(title = "讨论收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumFavorite forumFavorite)
    {
        return toAjax(forumFavoriteService.insertForumFavorite(forumFavorite));
    }

    /**
     * 修改讨论收藏
     */
    @PreAuthorize("@ss.hasPermi('forum:favorite:edit')")
    @Log(title = "讨论收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumFavorite forumFavorite)
    {
        return toAjax(forumFavoriteService.updateForumFavorite(forumFavorite));
    }

    /**
     * 删除讨论收藏
     */
    @PreAuthorize("@ss.hasPermi('forum:favorite:remove')")
    @Log(title = "讨论收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(forumFavoriteService.deleteForumFavoriteByFavoriteIds(favoriteIds));
    }
}
